/*
 * @Description: 
 * @Version: 2.0
 * @Autor: ftt
 * @Date: 2022-04-22 11:44:52
 * @LastEditors: TT
 * @LastEditTime: 2023-03-21 08:48:17
 */
import 'package:flutter/material.dart';
import '../ttcomment.dart';

/*
 * @description: 默认弹框
 * @param
 * {
 *    title: 提示语
 *    msg: 显示内容
 *    cannermsg: 取消按钮文字
 *    suremsg: 确定按钮文字
 *    btntype:  按钮样式 1 两个按钮 2 一个按钮
 *    barrierDismissible: 点击屏幕关闭弹框
 * }
 * @return {*}
 */
showPermissionpopup({
  required BuildContext context,
  String? title,
  String? msg,
  String? suremsg = "同意",
  String? cannermsg = "我不同意",
  int btntype = 1,
  Widget? titlewidget,
  Widget? msgwidget,
  bool barrierDismissible = true,
  Widget? child,
  Color? dialogBackColor,
  Color? surebackgrounColor,
  Widget? sureWidget,
  Widget? cannerWidget,
  Function()? ontapsure,
  Function()? ontapcanner,
}) {
  showDialog(
    context: context,
    barrierDismissible: barrierDismissible,
    builder: (BuildContext context) {
      return Dialog(
        backgroundColor: dialogBackColor,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.all(
            Radius.circular(
              15.r,
            ),
          ),
        ),
        child: child ??
            PopDialogWidget(
              context: context,
              title: title,
              msg: msg,
              titlewidget: titlewidget,
              msgwidget: msgwidget,
              cannermsg: cannermsg,
              suremsg: suremsg,
              btntype: btntype,
              sureWidget: sureWidget,
              cannerWidget: cannerWidget,
              surebackgrounColor: surebackgrounColor,
              ontapcanner: () {
                if (ontapcanner != null) {
                  ontapcanner();
                } else {
                  Navigator.of(context).pop();
                }
              },
              ontapsure: () {
                if (ontapsure != null) {
                  ontapsure();
                } else {
                  Navigator.of(context).pop();
                }
              },
            ),
      );
    },
  );
}

/*
 * @description:创建通用弹框界面
 * @param
 * {
 *    title: 提示语
 *    msg: 显示内容
 *    cannermsg: 取消按钮文字
 *    suremsg: 确定按钮文字
 * 
 *    btntype:  按钮样式 1 两个按钮 2 一个按钮
 *    ontapsure type 0 取消 1 确定
 * }
 * @return {*}
 */
// ignore: non_constant_identifier_names
Widget PopDialogWidget(
    {required BuildContext context,
    String? title,
    Widget? titlewidget,
    Widget? msgwidget,
    String? msg,
    String? cannermsg,
    String? suremsg,
    Color? surebackgrounColor,
    Widget? sureWidget,
    Widget? cannerWidget,
    int btntype = 1,
    double msgAndBtnLineSpace = 20,
    Function()? ontapsure,
    Function()? ontapcanner}) {
  return Padding(
    padding: EdgeInsets.all(20.w),
    child: Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        titlewidget ??
            Text(
              title ?? "",
              style: TextStyleMacor.fontBold(
                16,
                CommentColorS.col222222,
              ),
              textAlign: TextAlign.center,
            ),
        title == null ? Gaps.vGap5 : Gaps.vGap10,
        msgwidget ??
            Text(
              msg ?? "",
              style: TextStyleMacor.fontBold(
                16,
                CommentColorS.col222222,
              ),
            ),
        SizedBox(
          height: msgAndBtnLineSpace,
        ),
        CreateSureAndCannerBtnWidget(
          cannermsg: cannermsg,
          suremsg: suremsg,
          btntype: btntype,
          ontapcanner: ontapcanner,
          surebackgrounColor: surebackgrounColor,
          sureWidget: sureWidget,
          cannerWidget: cannerWidget,
          ontapsure: ontapsure,
        )
      ],
    ),
  );
}

/*
 * @description: 创建 通用的两个按钮
 * @param {
 *    cannermsg: 取消按钮文字
 *    suremsg: 确定按钮文字
 *    btntype:  按钮样式 1 两个按钮 2 一个按钮
 *    ontapsure type 0 取消 1 确定}
 * @return {*}
 */
// ignore: non_constant_identifier_names
CreateSureAndCannerBtnWidget({
  String? cannermsg,
  String? suremsg,
  Color? surebackgrounColor,
  Widget? sureWidget,
  Widget? cannerWidget,
  int btntype = 1,
  Function()? ontapsure,
  Function()? ontapcanner,
}) {
  return Row(
    mainAxisAlignment: btntype == 1
        ? MainAxisAlignment.spaceBetween
        : MainAxisAlignment.center,
    children: [
      btntype == 1
          ? cannerWidget ??
              BtnItemWidget(
                BtnlayoutType.text,
                title: Container(
                  alignment: Alignment.center,
                  width: 112,
                  height: 40.h,
                  decoration: BoxDecoration(
                    color: CommentColorS.colf5f5f5,
                    borderRadius: BorderRadius.all(
                      Radius.circular(40.r),
                    ),
                  ),
                  child: Text(
                    cannermsg ?? "",
                    style: TextStyleMacor.fontBold(14, CommentColorS.col999999),
                  ),
                ),
                ontap: () {
                  if (ontapcanner != null) {
                    ontapcanner();
                  }
                },
              )
          : Container(),
      btntype == 1 ? Gaps.hGap20 : Container(),
      sureWidget ??
          BtnItemWidget(
            BtnlayoutType.text,
            title: Container(
              alignment: Alignment.center,
              width: btntype == 1 ? 112 : 150.w,
              height: 40.h,
              decoration: BoxDecoration(
                  borderRadius: BorderRadius.all(
                    Radius.circular(40.r),
                  ),
                  color: surebackgrounColor ?? CommentColorS.col2865ff),
              child: Text(
                suremsg ?? "",
                style: TextStyleMacor.fontBold(14, CommentColorS.colffffff),
              ),
            ),
            ontap: () {
              if (ontapsure != null) {
                ontapsure();
              }
            },
          )
    ],
  );
}
